import 'package:flutter/material.dart';
import 'package:helloflutter/page/search.dart';
import 'package:helloflutter/page/tabs/home.dart';

final routes = {
  '/':(context)=>const TestBody(),
  '/search': (context, {arguments}) => SearchPage(arguments: arguments),
  '/home': (context, {arguments}) => const Home(),
};

Route<dynamic>? defaultOnGenerateRoute(RouteSettings settings) {
  final String name = settings.name!;
  final Function pageContentBuilder = routes[name]!;
  // if (pageContentBuilder != null) {
  if (settings.arguments != null) {
    final Route route = MaterialPageRoute(
        builder: (context) =>
            pageContentBuilder(context, arguments: settings.arguments));
    return route;
  } else {
    final Route route =
        MaterialPageRoute(builder: (context) => pageContentBuilder(context));
    return route;
  }
  // }
}


class TestBody extends StatelessWidget {

  const TestBody({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: ListView(
        children: [
          const Text("Hello Flutter!"),
          ElevatedButton(
            onPressed: () {
              Navigator.pushNamed(context, "/search",arguments: {"test":"ABC TEST"});
            },
            child: const Text("search"),
          ),
          ElevatedButton(
            onPressed: () {
              Navigator.pushNamed(context, "/home");
            },
            child: const Text("home"),
          ),
        ],
      ),
    );
  }
}

